<?php
namespace app\kucun\controller;

use app\kucun\model\WxWorkUserModel;
use QiyeWork\QiyeWorkService;
use app\kucun\model\ShopModel;

/**
 * Class Index
 * @package app\index\controller
 */
class Shop extends Base
{


    // 新增产品
    public function add(){
        $shop_name = input('shop_name', '', 'string');
        $id = input('id', 0, 'intval');
        if(empty($shop_name)){
            return $this->returnError([], '产品名称不能为空');
        }
        $data = [];
        $data['shop_name'] = $shop_name;
        $data['update_time'] = time();
        $data['status'] = 1;
        if($id){
            $productModel = new ShopModel();
            $res = $productModel->where('id', $id)->update($data);
            if($res){
                return $this->returnSuccess($res, '修改成功');
            }else{
                return $this->returnSuccess($res, '修改失败');
            }
        }else{
            $data['create_time'] = time();
            $productModel = new ShopModel();
            $res = $productModel->insert($data);
            if($res){
                return $this->returnSuccess($res, '新增成功');
            }else{
                return $this->returnSuccess($res, '新增失败');
            }
        }

    }

    // 获取产品列表
    public function list(){
        $result = $this->_query((new ShopModel()), input())->page(false, false);
        return $this->returnSuccess($result);
    }

}